package com.chen.qmzy.service;

import com.chen.qmzy.dao.DwReceiverDao;
import com.chen.qmzy.entity.DwReceiverEntity;
import com.chen.qmzy.entity.ResultEntity;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class DwReceiverService  {
    private static final Logger logger= LoggerFactory.getLogger(DwReceiverService.class);//日志getLogger需要传入的类名
    @Resource
    DwReceiverDao dwReceiverDao;

    /**
     * 添加地址
     * @param receiver 用户姓名
     * @param cellPhone 电话号码
     * @param city 城市
     * @param county 市区
     * @param address 详细地址
     * @param areacode 邮政
     * @param isDefault 是否默认地址
     * @return String
     */
    public boolean addReceiver(int userId,String receiver,String cellPhone,String province,String city,String county,String address,String areacode,int isDefault){
        try{
            return dwReceiverDao.addReceiver(userId,receiver, cellPhone, province,city, county, address, areacode, isDefault);
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return true;
        }
    }

    /**
     * 删除
     * @param id 根据id删除
     * @return String
     */
    public Boolean delReceiver(int id){
            return dwReceiverDao.delReceiver(id)>0;

    }

    /**
     * 根据id修改用户信息
     * @return String
     */
    public boolean upReceiver(int userId,String receiver,String cellPhone,String city,String county,String address,String areacode,int isDefault,int id){
        try{
            return dwReceiverDao.upReceiver(userId,receiver, cellPhone, city, county, address, areacode, isDefault, id);
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return true;
        }
    }

    /**
     * 查询地址列表信息
     * @return Sting
     */
    public String getReceiverList(int userId){
        try{
            return ResultEntity.success(dwReceiverDao.getReceiverList(userId));
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10005);
        }
    }

    /**
     * 查询默认地址
     * @param userId
     * @return
     */

    public DwReceiverEntity selectDefaultByUserId(int userId){
        try{
            return dwReceiverDao.selectDefaultByUserId(userId);
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return null;
        }
    }

    /**
     * 根据id查询用户详情信息
     * @param id id
     * @return String
     */
    public DwReceiverEntity getReceiverDetailList(int id){
        try{
            return  dwReceiverDao.getReceiverDetailList(id);
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
            return null;
        }
    }

}
